package com.suxin.splitter.executor;

import com.suxin.splitter.MethodExecutor;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
 * @author Tang
 * @classname AbstractMethodExecutor
 * @description [  ]
 * @date 2022/11/7 13:44
 */
public abstract class AbstractMethodExecutor implements MethodExecutor {

    @Override
    public <P, R> List<R> execute(Function<P, R> function, List<P> ps) throws Exception {
        if (CollectionUtils.isEmpty(ps)) {
            return Collections.emptyList();
        }
        return doExecute(function,ps);
    }

    /**
     * 子类扩展点
     * @param function
     * @param ps
     * @param <R>
     * @param <P>
     * @return
     */
    protected abstract <P, R> List<R> doExecute(Function<P, R> function, List<P> ps) throws Exception;

}
